package com.ja.openchat.ui.chat.remittance;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.ja.openchat.R;
import com.lxj.xpopup.core.CenterPopupView;
import com.lxj.xpopup.util.XPopupUtils;

public class RefundTranferMoneyDialog extends CenterPopupView {

    private OnTransferRefundCallback callback;
    private String toUserName;
    public RefundTranferMoneyDialog(@NonNull Context context, String toUserName,OnTransferRefundCallback callback) {
        super(context);
        this.callback = callback;
        this.toUserName = toUserName;
    }


    private String cancleText,okText,content;

    public RefundTranferMoneyDialog(@NonNull Context context, String cancleText, String okText, String content,OnTransferRefundCallback callback) {
        super(context);
        this.callback = callback;
        this.cancleText = cancleText;
        this.okText = okText;
        this.content = content;
    }

    @Override
    protected int getPopupWidth() {
        return (int) (XPopupUtils.getAppWidth(getContext()) * .85f);
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_tranfer_money_to_refund;
    }


    @Override
    protected void onCreate() {
        super.onCreate();
        TextView title = findViewById(R.id.title);
        if(!TextUtils.isEmpty(toUserName)){
            title.setText(String.format(getContext().getString(R.string.refund_transfer_text),toUserName));
        }else if(!TextUtils.isEmpty(content)){
            title.setText(content);
        }
        TextView cancle_btn = findViewById(R.id.cancle_btn);
        if(!TextUtils.isEmpty(cancleText)){
            cancle_btn.setText(cancleText);
        }
        cancle_btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        TextView ok_btn = findViewById(R.id.ok_btn);
        if(!TextUtils.isEmpty(okText)){
            ok_btn.setText(okText);
        }
        ok_btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if(callback!=null){
                    callback.doRefund();
                }
                dismiss();
            }
        });
    }
}
